package com.yunji.coupon.enums;

import lombok.Getter;

/**
 * @author : peter-zhu
 * @date : 2024/10/23 17:08
 * @description : TODO
 **/
@Getter
public enum DiscountTypeEnum {

    SUBTRACT(1, "立减", "立减%.2f元"),
    DISCOUNT(2, "折扣", "折扣%.1f折");
    private final Integer code;
    private final String desc;
    private final String show;

    DiscountTypeEnum(Integer code, String desc, String show) {
        this.code = code;
        this.desc = desc;
        this.show = show;
    }

    public static String showByCode(Integer code, Double value) {
        for (DiscountTypeEnum discountTypeEnum : DiscountTypeEnum.values()) {
            if (discountTypeEnum.getCode().equals(code)) {
                String format = String.format(discountTypeEnum.getShow(), value);
                if (code.equals(DiscountTypeEnum.DISCOUNT.getCode())) {
                    return format.replace(".0", "");
                }
                return format;
            }
        }
        return null;
    }
}
